package com.bocai.eelly.fragments;

import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;

import com.bocai.eelly.R;
import com.bocai.eelly.activitys.FindAccessoriesActivity;
import com.bocai.eelly.activitys.FindFabricActivity;
import com.bocai.eelly.activitys.FindHuoDaiListActivity;
import com.bocai.eelly.activitys.FindNewProductListActivity;
import com.bocai.eelly.activitys.FindStockActivity;
import com.bocai.eelly.activitys.FindToolsListActivity;
import com.bocai.eelly.adapter.HomeAdp;
import com.bocai.eelly.common.BaseFragment;
import com.bocai.eelly.views.NoScrolGridView;

import butterknife.Bind;
import butterknife.ButterKnife;

public class PurchaserFragment extends BaseFragment implements AdapterView.OnItemClickListener{
    @Bind(R.id.ngl_home)
    NoScrolGridView nglHome;
    private View view;

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        view = LayoutInflater.from(getActivity()).inflate(R.layout.fragment_purchaser, null);
        initView();
        initEvent();
        return view;

    }

    private void initEvent() {
        nglHome.setOnItemClickListener(this);
    }

    private String[] texts={"找面料","找辅料","找货代","找库存","找工具设备","找新品"};
    private int[] pics={R.mipmap.ic_home_find_fabric,R.mipmap.ic_home_find_accessories,
            R.mipmap.ic_home_find_freight_forwarding,R.mipmap.ic_home_find_stock,
            R.mipmap.ic_home_find_tool,R.mipmap.ic_home_find_new};
    private void initView() {
        ButterKnife.bind(this, view);
        nglHome.setFocusable(false);
        nglHome.setAdapter(new HomeAdp(getActivity(),texts,pics));

    }

    @Override
    public void onDestroyView() {
        super.onDestroyView();
        ButterKnife.unbind(this);
    }

    @Override
    public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
        switch (position)
        {
            case 0:
                startActivity(new Intent(getActivity(), FindFabricActivity.class));
                break;
            case 1:
                startActivity(new Intent(getActivity(), FindAccessoriesActivity.class));
                break;
            case 2:
                startActivity(new Intent(getActivity(), FindHuoDaiListActivity.class));
                break;
            case 3:
                startActivity(new Intent(getActivity(), FindStockActivity.class));
                break;
            case 4:
                startActivity(new Intent(getActivity(), FindToolsListActivity.class));
                break;
            case 5:
                startActivity(new Intent(getActivity(), FindNewProductListActivity.class));
                break;
        }
    }
}
